<!doctype html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="../vendor/bootstrap-icons/font/bootstrap-icons.css">
    <link rel="stylesheet" href="../vendor/bootstrap-5.3.0-alpha1/dist/css/bootstrap.min.css">
    <title>bs</title>

<body>

<div class="container p-2">
    <div class="row g-2">
        <div class="col-md-6">
            <div class="qtab"></div>

        </div>
        <div class="col-md-6">
            <button class="btn btn-success mt-2 btn1">添加tab</button>
            <button class="btn btn-success mt-2 btn3">主页面开启黑暗模式</button>
            <div>给外部页面也开启黑暗模式效果更佳</div>
            <button class="btn btn-success mt-2 btn2">设置子页面属性</button>
        </div>
    </div>
</div>


<script src="../vendor/bootstrap-5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
<script src="../vendor/jquery/dist/jquery.min.js"></script>
<script src="../vendor/bootstrap-quicktab/dist/js/bootstrap-quicktab.min.js"></script>

<script>
    $(function () {

        var qtab = new Quicktab({
            selector: '.qtab',
            //默认初始化tab
            tabs: [
                {title: '页面1', url: 'child3.html?a=1'},
                {title: '页面2', url: 'child3.html?a=2'},
            ]
        });


        //添加tab
        $('.btn1').on('click', function () {
            var num = Math.round(Math.random() * (100000 - 1) + 1);
            qtab.addTab({
                //标题
                title: "新标签页" + num,
                //连接
                url: 'child3.html?randow=' + num,
                //是否可以关闭
                close: true,
            })
        });

        $('.btn2').on('click', function () {
            //实例调用setTab方法，给tab里面的iframe设置黑暗模式
            Quicktab.get('.qtab').setTab(function (tabsArr) {
                //所有的tab信息数组
                // console.log(tabsArr);

                //遍历处理每个tab
                $.each(tabsArr, function (index, tab) {
                    //判断tab是否有iframe元素(因为有的tab它是惰性的,不激活是没有面板内容的)，且该iframe不是跨域的。
                    if (tab.tabIFrame.el !== null && tab.tabIFrame.canAccess === true) {
                        $(tab.tabIFrame.el.contentDocument).find('html').attr('data-bs-theme', 'dark');
                    }
                })
            });
        });

        $('.btn3').on('click', function () {
            $('html').attr('data-bs-theme', 'dark');
        });
    })


</script>

</body>
</html>
